home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_145 / tinyprolog / prolog.h < prev   
Text File  |  1992-05-06  |  4KB  |  109 lines

  1. /* Copyright 1986 - MicroExpert Systems
  2.                     Box 430 R.D. 2
  3.                     Nassau, NY 12123       */
  4.  
  5. /* Revisions - 1.1  Nov. 1986   - Edinburgh list syntax added */
  6. /* converted to lattice c by Dennis J. Darland [73300,270] 11/9/87 */
  7. /* VTPROLOG implements the data base searching and pattern matching of
  8.    PROLOG. It is described in "PROLOG from the Bottom Up" in issues
  9.    1 and 2 of AI Expert.
  10.  
  11.    We would be pleased to hear your comments, good or bad, or any applications
  12.    and modifications of the program. Contact us at:
  13.  
  14.      AI Expert
  15.      CL Publications Inc.
  16.      650 Fifth St.
  17.      Suite 311
  18.      San Francisco, CA 94107
  19.  
  20.    or on the AI Expert BBS. Our id is BillandBev Thompson ,[76703,4324].
  21.    You can also contact us on BIX, our id is bbt.
  22.  
  23.    Bill and Bev Thompson    */
  24.  
  25. #define debug 0
  26. #define back_space 8
  27. #define tab '\t'
  28. #define eof_mark 26
  29. #define esc 27
  30. #define quote_char 39
  31. #define left_arrow 75
  32. #define end_key = 79
  33. #define del_line 24
  34. #define bell 7
  35.  
  36. #define true 1
  37. #define false 0
  38.  
  39. #define MAX_ALLOC 1000
  40.  
  41. typedef int counter;
  42. typedef unsigned char boolean; 
  43. enum   node_type {consnode,func,variable,constant,freenode}; 
  44. typedef struct node_struct
  45.     {
  46.     boolean in_use;
  47.     enum node_type tag;
  48.     struct chain_struct
  49.         {
  50.         struct node_struct    *next_in_chain;
  51.         } chain_node_ptr;
  52.     union  {
  53.            struct cons_struct
  54.                    {
  55.                 struct node_struct  *tail_ptr;
  56.                 struct node_struct  *head_ptr;
  57.                 } cons_node;
  58.            char string_data[80];
  59.             } node_union;
  60.     } node;
  61.  
  62. /* node is the basic allocation unit for lists. The fields are used as
  63.    follows:
  64.  
  65.     in_use     - in_use = false tells the garbage collector that this node
  66.                  is available for re-use.
  67.     tag        - which kind of node this is.
  68.     cons_node  - cons_nodes consist of two pointers. one to the head (first item)
  69.                  the other to the rest of the list. They are the "glue" which
  70.                  holds the list together. The list (A B C) would be stored as
  71.                    -------         --------          --------
  72.                    | .| . |----->  |  .| . |------> |  .| . |---> NIL
  73.                    --|-----         --|------        --|-----
  74.                      |                |                |
  75.                      V                V                V
  76.                      A                B                C
  77.  
  78.                  The boxes are the cons nodes, the first part of the box
  79.                  holds the head pointer, then second contains the tail.
  80.     constant   - holds string values, we don't actually use the entire 80
  81.                  characters in most cases.
  82.     variable   - also conatins a string value, these nodes will be treated as
  83.                  PROLOG variables rather than constants.
  84.     free_node  - the garbage collector frees all unused nodes. */
  85.  
  86.  
  87.     char    line[132],saved_line[132];
  88.     unsigned char    token[80];
  89.     FILE    *source_file;
  90.     boolean    error_flag,in_comment;
  91.      node    *data_base,*saved_list;
  92.     int        chain_cnt;
  93.     node     *chain_head;
  94.     
  95. /* The important globals are:
  96.    source_file  - text file containing PROLOG statements.
  97.    line         - line buffer for reading in the text file
  98.    saved_list   - list of all items that absolutely must be saved if garbage
  99.                   collection occurs. Usually has at least the data_base and
  100.                   the currents query attached to it.
  101.    data_base    - a pointer to the start of the data base. It points to a
  102.                   node pointing to the first sentence in the data base. Nodes
  103.                   pointing to sentences are linked together to form the data
  104.                   base.
  105.    delim_set    - set of characters which delimit tokens. 
  106.    chain_cnt    - total number of nodes malloc'ed.
  107.    chain_head    - head to chain of all malloc'ed nodes. */
  108.  
  109.